//
//  AppViewController.m
//  ConnectSocialNetwork
//
//  Created by Mac Center on 7/11/13.
//  Copyright (c) 2013 Mac Center. All rights reserved.
//

#import "AppViewController.h"
#import <QuartzCore/QuartzCore.h>


@interface AppViewController ()

@end

@implementation AppViewController
@synthesize listOfViewController = _listOfViewController;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


static AppViewController *m_Instance;
+ (AppViewController *)Shared
{
    if ( !m_Instance ) {
        m_Instance = [[AppViewController alloc] init];
    }
    return m_Instance;
}

#pragma mark - Indicator view animation

- (void)isRequesting:(BOOL)isRe andRequestType:(ENUM_API_REQUEST_TYPE)type andFrame:(CGRect)frame {
    if (isRe) {
        if (_requestingView == nil) {
            _requestingView = [UIView new];
            _requestingView.backgroundColor = [UIColor blackColor];
            _requestingView.alpha= 0.5;
        }
        if (_requestingIndicator == nil) {
            _requestingIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
            [_requestingView addSubview:_requestingIndicator];
            
        }
        
        [_requestingView removeFromSuperview];
        [_requestingIndicator startAnimating];
		_requestingView.frame = frame;
        _requestingView.layer.masksToBounds = NO;
        _requestingView.layer.cornerRadius = 0;
		_requestingIndicator.center = CGPointMake(frame.size.width / 2, frame.size.height / 2);
        
        [[[_listOfViewController lastObject] view] addSubview:_requestingView];
        [[[_listOfViewController lastObject] view] bringSubviewToFront:_requestingView];
        
        NSArray *views = [[[_listOfViewController lastObject] view] subviews];
        for (UIView *view in views) {
            VKLog(@"view-%@-%@--%f--%f",view,view.description,view.frame.size.height,view.frame.size.width);
        }
    }
    else {
        [_requestingIndicator stopAnimating];
        [_requestingView removeFromSuperview];
    }
}

- (void)isRequesting:(BOOL)isRe andRequestType:(ENUM_API_REQUEST_TYPE)type andFrame:(CGRect)frame andcornerRadius:(NSInteger) cornerRadius {
    if (isRe) {
        if (_requestingView == nil) {
            _requestingView = [UIView new];
            _requestingView.backgroundColor = [UIColor blackColor];
            _requestingView.alpha= 0.5;
        }
        if (_requestingIndicator == nil) {
            _requestingIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
            [_requestingView addSubview:_requestingIndicator];
            
        }
        
        [_requestingView removeFromSuperview];
        [_requestingIndicator startAnimating];
        _requestingView.layer.masksToBounds = YES;
        _requestingView.layer.cornerRadius = cornerRadius;
		_requestingView.frame = frame;
		_requestingIndicator.center = CGPointMake(frame.size.width / 2, frame.size.height / 2);
        [[[_listOfViewController lastObject] view] addSubview:_requestingView];
    }
    else {
        [_requestingIndicator stopAnimating];
        [_requestingView removeFromSuperview];
    }
}


@end
